﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace sharpCmd.Controls.Viewers
{
    internal class ViewerControl : UserControl,IDisposable
    {
        public ViewerControl()
        {
            BackColor = Color.White;
            Dock = DockStyle.Fill;
        }

        /// <summary>
        /// Gets an appropriate ViewerControl for specified type
        /// </summary>
        /// <param name="viewerType"></param>
        /// <returns></returns>
        internal static ViewerControl Get(ViewerType viewerType)
        {
            switch (viewerType)
            {
                case ViewerType.Text:
                    return new TextViewer();
                default:
                    throw new NotImplementedException();
            }
        }

        public virtual void Display()
        {
            throw new InvalidOperationException();
        }

        public void Initialize()
        {
            Reader = new StreamReader(new FileStream(SelectedFile, FileMode.Open, FileAccess.Read));
        }

        protected override void Dispose(bool disposing)
        {
            Reader.Close();
            Reader.Dispose();
            base.Dispose(disposing);
        }

        protected StreamReader Reader { get; private set; }
        public string SelectedFile { get; set; }
        public long Position { get; set; }

        private bool wordWrap;
        protected event EventHandler WordWrapChanged;
        public bool WordWrap
        {
            get { return wordWrap; }
            set
            {
                wordWrap = value;
                if (WordWrapChanged != null)
                    WordWrapChanged(null, null);
            }
        }
    }
}